package com.lecture.java8.datastructure;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2021/4/8 14:36
 */
public class ArrayQueue {

    private String[] item;
    private int n;

    private int head;
    private int tail;

    public ArrayQueue(int n) {
        item = new String[n];
        this.n = n;
    }

    //入队
    public boolean enqueue(String item) {
        // 如果tail == n表示队列已经满了
        if (tail == n) {
            return false;
        }
        this.item[tail] = item;
        tail ++;
        return true;
    }

    //出队
    public String dequeue() {
        if (head == tail) {
            return null;
        }
        String ret = this.item[head];
        head ++;
        return ret;
    }

    public static String validateFileDir(String fileName, String permitDirectory) throws Exception{
        File file= new File(fileName);
        String canonicalFilePath= file.getCanonicalPath();
        File permitDir = new File(permitDirectory);
        String canonicalPermitDir = permitDir.getCanonicalPath();
        if (canonicalFilePath.startsWith(canonicalPermitDir)){
            return canonicalFilePath;
        }else{
            throw new IllegalStateException("文件不在许可的目录内");
        }
    }

    public static void main(String[] args) throws IOException {
        File file = new File("F:\\tmp\\123\\../1.txt");
        file.mkdirs();
    }

}
